﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crossroad.Utils.Extensions;
using SqlSugar;

namespace Crossroad.System.Admin.Model
{
    ///<summary>
    ///系统菜单
    ///</summary>
    [SugarTable("admin_menu")]
    public partial class Menu : ModelContext
    {
        public Menu()
        {
            LoadDefVal();
        }

        public Menu(bool loadDef)
        {
            if (loadDef)
                LoadDefVal();
        }

        public void LoadDefVal()
        {
            this.parentId = 0;
            this.creatorId = Convert.ToInt32("0");
            this.sort = Convert.ToInt32("99");
            this.updateTime = Convert.ToInt32("0");
            this.updatorId = Convert.ToInt32("0");
            this.createTime = Convert.ToInt32("0");
        }

        /// <summary>
        /// Desc:创建人
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "creator_id")]
        public int? creatorId { get; set; }

        /// <summary>
        /// Desc:连接地址
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string path { get; set; }

        /// <summary>
        /// Desc:图标代码
        /// Default:
        /// Nullable:False
        /// </summary>           
        public string icon { get; set; }

        /// <summary>
        /// Desc:排序
        /// Default:99
        /// Nullable:True
        /// </summary>           
        public int? sort { get; set; }

        /// <summary>
        /// Desc:id
        /// Default:
        /// Nullable:False
        /// </summary>           
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int id { get; set; }

        /// <summary>
        /// Desc:类型 0.前台,1.后台
        /// Default:
        /// Nullable:False
        /// </summary>           
        [SugarColumn(ColumnName = "type_id")]
        public int typeId { get; set; }

        /// <summary>
        /// Desc:菜单标题
        /// Default:
        /// Nullable:False
        /// </summary>           
        public string label { get; set; }

        /// <summary>
        /// Desc:修改时间
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "update_time")]
        public int? updateTime { get; set; }

        /// <summary>
        /// Desc:层级id列表 ids
        /// Default:
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "layer_list")]
        public string layerList { get; set; }

        /// <summary>
        /// Desc:修改人
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "updator_id")]
        public int? updatorId { get; set; }

        /// <summary>
        /// Desc:深度(层级)
        /// Default:
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "layer_num")]
        public int? layerNum { get; set; }

        /// <summary>
        /// Desc:组件
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string component { get; set; }

        /// <summary>
        /// Desc:操作id列表
        /// Default:
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "option_ids")]
        public string optionIds { get; set; }

        /// <summary>
        /// Desc:创建时间
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "create_time")]
        public int? createTime { get; set; }

        /// <summary>
        /// Desc:父级id
        /// Default:
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "parent_id")]
        public int? parentId { get; set; }


        #region 扩展属性

        private string _createTimeText;
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string createTimeText
        {
            set { _createTimeText = value; }
            get
            {
                if (_createTimeText.IsNullOrEmpty())
                    return _createTimeText = (createTime ?? 0).ToDateTimeStr();

                return _createTimeText;
            }
        }

        /// <summary>
        /// 创建人
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string creatorName { set; get; } = string.Empty;

        private string _updateTimeText;
        /// <summary>
        /// 修改时间
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string updateTimeText
        {
            set { _updateTimeText = value; }
            get
            {
                if (_updateTimeText.IsNullOrEmpty())
                    return _updateTimeText = (updateTime ?? 0).ToDateTimeStr();

                return _updateTimeText;
            }
        }

        /// <summary>
        /// 修改人
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string updatorName { set; get; } = string.Empty;

        /// <summary>
        ///  父级菜单标题
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string parentLabel { get; set; } = string.Empty;

        /// <summary>
        /// 子节点
        /// </summary>
        public List<Menu> children;

        /// <summary>
        /// meta
        /// </summary>
        public Dictionary<string, object> meta = new Dictionary<string, object>();

        /// <summary>
        /// 操作列表
        /// </summary>
        public List<Option> options = new List<Option>();

        #endregion
    }
}
